﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="HousePersonAddForm.aspx.cs" Inherits="FantastPlatform.Community.UI.InfoCollection.HousePersonAddForm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
            <script type="text/javascript">
                var hpaf = new FantastPlatform.UI.HousePersonAddForm({
                    renderTo: 'hpaf_div',
                    HouseHoldId: '<%=GetId() %>',
                    url: '../Service/HousePersonAddService.aspx?Action=Add',
                    tbar: [{
                        text: '保存',
                        iconCls: 'save',
                        handler: function () {
                            if (typeof (hpag) == 'undefined') {
                                submitPanelJson2(hpaf, currtWind, null);
                            } else {
                                submitPanelJson2(hpaf, currtWind, hpag);
                            } 
                        }
                    }, '-', {
                        text: '重置',
                        iconCls: 'cancel',
                        handler: function () { hpaf.form.reset(); }
                    }
]
                })
                function submitPanelJson2(form, sender, grid, fn, data) {
                    if (form.form.isValid()) {
                        var myMask = new Ext.LoadMask(sender.getEl(), {
                            msg: "正在保存数据,请稍候...."
                        });
                        var purPose = form.form.findField('Purpose').getValue();
                        var houseDistrict = form.form.findField('HouseDistrict').getValue();                      

                        var dataStr = '{';
                        if (form.form.getValues().Id == undefined) {
                            dataStr += '"Id":0,';
                        } else {
                            dataStr += '"Id":' + form.form.getValues().Id + ',';
                        }
                        dataStr += '"Number":"' + form.form.getValues().Number + '",';
                       dataStr += '"CreateDate":"' + form.form.getValues().CreateDate + '",';
                       dataStr += '"Enable":"' + form.form.getValues().Enable + '",';
                       dataStr += '"Deadline":"' + form.form.getValues().Deadline + '"';
                        //            dataStr += '"Owner":' + form.form.getValues().Owner[0] + ',';
                        //            dataStr += '"Leader":"' + form.form.getValues().Leader[0] + ',';
                        dataStr += "}";
                        if (data) {
                            dataStr = dataStr.substring(0, dataStr.length - 1) + "," + data + "}";
                        }
                        var url = '../Service/HousePersonAddService.aspx?Action=Add';
                        myMask.show();
                        Ext.Ajax.request({
                            method: 'post',
                            url: url,
                            params: { data: dataStr, HouseDistrict: houseDistrict, Purpose: purPose },
                            success: onSuccess,
                            failure: onFailure
                        });
                        function onFailure(request, options) {
                            myMask.hide();
                            showErrorMessage('操作失败', request.responseText, '');
                        }
                        function onSuccess(request, options) {
                            // 服务器返回json形式的结果
                            myMask.hide();
                            var reText = request.responseText;
                            var reTextObj = Ext.util.JSON.decode(reText);
                            if (eval(reTextObj.success)) {
                                showMessage('操作成功', '保存成功');
                                if (grid)
                                    updata(grid);
                                if (fn)
                                    fn.call(this, reText);
                                if (sender)
                                    sender.close();
                            } else {
                                showErrorMessage('操作失败', reTextObj.message, '');
                            }
                        }

                    }
                };
    </script>
</head>
<body>
    <div id="hpaf_div">
    
    </div>
</body>
</html>
